class Solution {
    public int missingNumber(int[] nums) {
       int left = 0;
       int rigth = nums.length;
       if(nums.length == 1) {
           if(nums[0] == 1) {
               return 0;
           }
           return 1;
       }
       if((rigth-1) == nums[rigth-1]) {
           return rigth;
       }
       while(left < rigth) {
           if(left != nums[left]) {
               return left;
           }
           if(rigth != nums[rigth - 1]) {
               return rigth;
           }
           left++;
           rigth--;
       }
       if(left == rigth && left != nums[left]) {
           return left;
       }
       return 0;
    }
}